package com.nfIt.dao.impl;

import com.nfIt.Dbutils.c3p0Dbutil;
import com.nfIt.dao.StaffsDao;
import com.nfIt.pojo.staffs;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * ClossName:staffsDaoImpl
 * Pakage:com.nfIt.Dao
 * Description
 *
 * @Author L
 * @Create 2024/3/6 20:20
 * @Version 2023.1.3
 */
public class StaffsDaoImpl implements StaffsDao {

    QueryRunner qr = new QueryRunner(c3p0Dbutil.getDataSource());

    @Override
    public int insertStaffs(staffs s) {
        int rows = 0;
        String sql = "insert into staffs(name,age,phone,pos,add_time,update_time) values(?,?,?,?,?,?)";

        try {
            rows = qr.update(sql,s.getName(),s.getAge(),s.getPhone(),s.getPos(),s.getAdd_time(),s.getUpdate_time());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return rows;
    }

    @Override
    public List<staffs> staffsAll() {


        String sql = "select id,name,age,phone,pos,add_time,update_time from staffs";
        List<staffs> list=null;
        try {
             list =qr.query(sql,new BeanListHandler<staffs>(staffs.class));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return list;
    }

    @Override
    public staffs staffsSeleId(int id) {
        staffs s = new staffs();
        String sql = "select id,name,age,phone,pos,add_time,update_time from staffs where id=?";


        try {
            s = (staffs) qr.query(sql,new BeanListHandler<staffs>(staffs.class),id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return s;
    }

    @Override
    public List<staffs> staffsSelePag() {

        return null;
    }

    @Override
    public int staffsDeleId(int id) {


        int rows = 0;
        return rows;
    }

    @Override
    public int staffsUpdaId(staffs s) {

        int rows = 0;
        return rows;
    }
}
